package BookStore.EBook.ConvertorForAndroid;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class ChapterSorter {


	public static List<String> getOrderedChapterNamesFromDB(String bookName, String DBServer, String DBName, String user, String password, boolean isIntegratedSecurity)
	{
		List<String> chapters = new ArrayList<String>();

        try{  
            Connection con = DBConnection.getConnection(DBServer, DBName, isIntegratedSecurity, user, password);
            //Connection con=DriverManager.getConnection(mConnectDB,user,password);
            Statement stmt=con.createStatement();

            String sql = "Select ChapterName FROM t_chapter where BookId in (select BookId from t_book where BookName='" + bookName + "') order by Created";
            ResultSet rs=stmt.executeQuery(sql);

            while(rs.next()){
            	chapters.add(rs.getString("ChapterName"));
            }
            stmt.close();
            con.close();
        }catch(SQLException e){  
            e.printStackTrace();  
        }  
        
		return chapters;
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		ChapterSorter.getOrderedChapterNamesFromDB("寸芒", "localhost:1433", "EB", "ads\\limin", "Bright19", true);

	}
}
